home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / dskut / njramd14.zip / NJRAMDX.ASM < prev    next >
Assembly Source File  |  1991-06-23  |  39KB  |  1,331 lines

  1. ; DEBUG   EQU TRUE
  2.  
  3. V286    EQU TRUE                        ; No XMS on 8088 PC's!
  4.  
  5. ;  Nifty James' Famous Expanded Memory Disk Drive
  6. ;  (C) Copyright 1987 by Mike Blaszczak.  All Rights Reserved
  7.  
  8. ;  Version 1.01  of  24 May 1987
  9. ;  Version 1.10  of  25 May 1987
  10. ;  Version 1.15  of  31 May 1987
  11. ;  Version 1.20  of  16 Oct 1987
  12.  
  13. ;  Modified Terje Mathisen 20 March 90
  14. ;  Version 1.02 of XMS-compatible NJRAMDX 14 Sep 1990
  15. ;  Version 1.40  of  23 Jun 1991 by Mike Blaszczak
  16.  
  17. ;  Shareware  $15     Please contribute!
  18.  
  19. ;  Assemble with
  20. ;    TASM NJRAMDX
  21. ;        (Comment out V286 EQU TRU for 8088 version.)
  22. ;    TLINK /t NJRAMDX, NJRAMDX.SYS
  23.  
  24. ;  --> DEVICE DRIVER FORMAT FILE <--
  25.  
  26. ; ---------------------------------------------------------------------------
  27.  
  28. ;   ASCII Characters
  29.  
  30. bell        equ    7        ; bell character
  31. tab        equ    9        ; tab character
  32. lf        equ    10        ; linefeed
  33. cr        equ    13        ; carriage return
  34. space        equ    32        ; space
  35. eos        equ    '$'        ; end of DOS string
  36.  
  37. ; ---------------------------------------------------------------------------
  38. ;   I/O Ports
  39.  
  40. Speak        equ    061h        ; speaker port
  41. SpeakMask    equ    011111110b    ; mask for speaker set bit
  42. SpeakToggle    equ    000000010b    ; toggle bit for the speaker
  43.  
  44. ; ---------------------------------------------------------------------------
  45. ;   DOS Calls
  46.  
  47. ; These are DOS functions used by the driver.
  48.  
  49. DisplayOut    equ    002h        ; call to print a single character
  50. PrintString    equ    009h        ; call to print a '$' string
  51. GetDOSVersion    equ    030h        ; call to get the DOS version #
  52.  
  53. ; ---------------------------------------------------------------------------
  54. ;  XMS Routines
  55.  
  56. ; These are the XMS functions that we use.  (These are specific functions
  57. ; of the XMS call.)
  58.  
  59. X_Counts    equ    08h        ; determine free/total mem
  60. X_Alloc        equ    09h        ; open, allocate, obtain handle ID
  61. X_Version    equ    00h        ; get the XMS version number
  62. X_Move        equ    0Bh        ; move an XMS block
  63.  
  64. ; ---------------------------------------------------------------------------
  65. ;  Driver Equates
  66.  
  67. ; This is the media descriptor byte.  Since our RAM drive is not 2 sided,
  68. ; does not have 8 sectors per track, and is not removable, we use 0F8h.
  69. ; At least, that's what the IBM DTR manual says.
  70.  
  71. MediaD        equ    0F8h
  72.  
  73. ; These are equates used by the driver.  They are all status and
  74. ; error flags, as defined in the DOS Technical Reference Manual.
  75.  
  76. ;                        FEDCBA9876543210 <- BIT NUMBERS
  77. errorflag    equ    01000000000000000b    ; error bit flag
  78. busystat    equ    00000001000000000b    ; busy status bit flag
  79. donestat    equ    00000000100000000b    ; done status bit flag
  80.  
  81. err_writeprot    equ    0        ; write protect violation
  82. err_badunit    equ    1        ; unknown unit number
  83. err_notready    equ    2        ; device not ready
  84. err_unknown    equ    3        ; unknown command
  85. err_CRC        equ    4        ; error CRC command
  86. err_reqlen    equ    5        ; bad request length
  87. err_seek    equ    6        ; seek failure
  88. err_badmedia    equ    7        ; bad media
  89. err_badsector    equ    8        ; sector not found
  90. err_badwrite    equ    10        ; write fault
  91. err_badread    equ    11        ; read fault
  92. err_general    equ    12        ; general failure
  93.  
  94. ; ---------------------------------------------------------------------------
  95. ;  Structure Definitions
  96.  
  97. ;  The structures defined here are used to find information in the
  98. ;  various request header formats.  Of course, being structures, they
  99. ;  don't take up space... they are used to define offsets for the
  100. ;  addressing of the request header.
  101.  
  102. rq    equ    es:bx            ; base address used in routines
  103.  
  104. ;  -- Request Header (General Format)
  105.  
  106. rhead    struc
  107.     rlen    db    ?    ; length of the structure
  108.     unitn    db    ?    ; unit number
  109.     command    db    ?    ; command code
  110.     status    dw    ?    ; status code (returned by us)
  111.         db    8 dup(?); reserved bytes
  112. rhead    ends
  113.  
  114.  
  115. ;  -- Request Header (INIT Command)
  116.  
  117. inithead    struc
  118.         db    (type rhead) dup (?)
  119.     units    db    ?    ; number of units
  120.     ndadro    dw    ?    ; ending address offset
  121.     ndadrs    dw    ?    ; ending address segment
  122.     bpboff    dw    ?    ; BPB offset pointer
  123.     bpbseg    dw    ?    ; BPB segment pointer
  124.     taglet    db    ?    ; drive tag letter
  125. inithead    ends
  126.  
  127. ;  -- Request Header (Media Check)
  128.  
  129. mediahead    struc
  130.         db    (type rhead) dup (?)
  131.     media    db    ?    ; our meida descriptor byte
  132.     change    db    ?    ; changed media flag
  133. mediahead    ends
  134.  
  135. ;  -- Request Header (Build BPB)
  136.  
  137. bbpbhead    struc
  138.         db    (type rhead) dup (?)
  139.         db    ?    ; media descriptor byte
  140.     baoff    dw    ?    ; transferr buffer address offset
  141.     baseg    dw    ?    ; transferr buffer address segment
  142.         dw    ?    ; BIOS parameter block pointer
  143.         dw    ?    ; BIOS parameter block pointer
  144. bbpbhead    ends
  145.  
  146. ;  -- Request Header (Read and Write)
  147.  
  148. rwhead        struc
  149.         db    (type rhead) dup (?)
  150.         db    ?    ; media descriptor byte
  151.     tbaoff    dw    ?    ; transferr buffer address offset
  152.     tbaseg    dw    ?    ; transferr buffer address segment
  153.     count    dw    ?    ; sector count
  154.     strtsec    dw    ?    ; starting sector number
  155. rwhead        ends
  156.  
  157.  
  158. ; With these headers defined as they are, access to the request header
  159. ; and command info fields is greatly simplified.  By setting ES:BX to
  160. ; point to the request header, the information can be easily referenced
  161. ; by using constructs such as
  162.  
  163. ;        mov    [rq.count],ax
  164. ;  or
  165. ;        mov    al,[rq.command]
  166.  
  167. ; Note that any part of the program can easily reference any particular
  168. ; command's structure, since the line
  169.  
  170. ;        db    (type rhead) dup (?)
  171.  
  172. ; makes all the command-specific structures "equivalent".
  173.  
  174. ; XMS Extended Memory Move structure
  175.  
  176. ExtendedMemoryMove     STRUC
  177.   NrOfBytes       dw 0,0
  178.   SourceHandle    dw 0
  179.   SourceOffset    dw 0,0
  180.   DestHandle      dw 0
  181.   DestOffset      dw 0,0
  182. ExtendedMemoryMove     ENDS
  183.  
  184. ; Check to see if this is the 286 version
  185.  
  186. ifdef  V286
  187.     .286
  188. ;    if1
  189.         %OUT    Enhanced processor version
  190. ;    endif
  191.     ifdef    PCL
  192. ;    if1
  193.         %OUT    for the PC's Limited 286/386
  194. ;    endif
  195.     endif
  196. else
  197. ;    if1
  198.         %OUT    Standard Version
  199. ;    endif
  200. endif
  201.  
  202. ;  This macro is used during debugging.  It prints a single character
  203. ; via the BIOS screen interface, and leaves the registers unchanged.
  204.  
  205. ifdef    DEBUG
  206.  
  207. ;    if1
  208.         %OUT  DEBUG Version
  209. ;    endif
  210.     PrintChar    macro    Char
  211.         ifdef    PCL
  212.  
  213.             push    ax
  214.             mov    al,Char
  215.             out    095h,al        ; put it digit 3 of smartvu
  216.             pop    ax
  217.  
  218.         else
  219.     
  220.             push    ax        ; save the regs
  221.             push    bx
  222.             push    dx
  223.             mov    ah,15
  224.             int    010h        ; get the current page
  225.             mov    al,Char
  226.             mov    ah,14        ; print the character
  227.             int    010h
  228.  
  229.             xor    dx,dx
  230.             mov    ah,0        ; also to printer
  231.             mov    al,Char
  232. ;            int    017h
  233.  
  234.             pop    dx
  235.             pop    bx        ;restore the regs
  236.             pop    ax
  237.  
  238.             endif
  239.             endm
  240.  
  241. else
  242.     PrintChar    macro    Char        ; if not debugging, blow it off
  243.             endm
  244. endif
  245.  
  246. ; ---------------------------------------------------------------------------
  247. ;  Public declarations for SYMDEB
  248.  
  249. ; These are public declarations included to allow SYMDEB to know where
  250. ; various lables and addresses are.  They are only needed for debugging,
  251. ; and serve no other useful purpose.
  252.  
  253. IF 1
  254.  
  255. PUBLIC NextPlace
  256. PUBLIC Attrib, JumpTable, TopCommand, RBPoint, RBPointOff, RBPointSeg, SaveSS
  257. PUBLIC SaveSP, StackTop, STRATPROC, Strategy
  258. PUBLIC INTPROC, Interrupt, FreakOut, IOCTLInput, ReadNoWait
  259. PUBLIC InputStatus, InputFlush, badcommand, BigLog, MC, MediaCheck
  260. PUBLIC BBPB, BuildBPB, BPBArray, OurBoot, OurBPB, SecSize, SecPerCluster
  261. PUBLIC RDirLen, DiskSize, SecPerFAT, BootCode
  262. PUBLIC RSEC, Read
  263. PUBLIC WSEC, Write
  264. PUBLIC TestValues, RangeError, SPEAKERCLICK, MakeClick
  265. PUBLIC SpeakerFlag, LastResident
  266. PUBLIC EatingWhite, GotOption
  267. PUBLIC NoBump, NotSilence, PagesLoop, LastDigit, NotPages, NotUseAll
  268. PUBLIC Unrecognized, EndOfLine, BigBust, ReTry
  269. PUBLIC GoodCombo, WipeOut
  270. PUBLIC CalcDiskFree, ClickOkay, MsgOkay, InitFail, GenFail, HowMuch
  271. PUBLIC RqdPages, MajorVersion, OurVolume, Banner, General
  272. PUBLIC NoEMMThere, EMMError, Init, NoMem, TooBig, BadOption, NoClicking
  273. PUBLIC Installed, DriveName, InstalledB, Installed2, UsedSpace, Bin2Dec
  274. PUBLIC Bin2DecLoop, Bin2DecDigit, WorkAreaL, WorkAreaH
  275.  
  276. ENDIF
  277.  
  278. ; ---------------------------------------------------------------------------
  279.  
  280. driver        segment    para public 
  281.         assume    cs:driver,ds:driver,es:driver,ss:driver
  282.  
  283.         org    0        ; drivers begin at zero
  284. firstplace    equ    this byte    ; this is the first byte
  285.  
  286. ; ---------------------------------------------------------------------------
  287. ;  Device Head